<?php
	include("initialize.php");
?>
<!--
List view for the class settings.

Classes are presented as a list, from which teachers can take action.

@author Rovelle Rodulfo
@suthor Chad Estioco
@version Second Semester, AY 2010-2011
-->
<html>
<head>
	<title>GradeGrid - Class Settings</title>
	<?php include("header.php"); ?>
	<?php include($dots . "boilerplate/php/write_functions.php");?>
	<script type="text/javascript" language="javascript">
		function deleteClass(classid, coursename, section){
			if(confirm("Are you sure you want to delete " + coursename + " - " + section + "?")){
				window.open("delete.php?in=" + classid, "_blank", "width=400, height=50")
			}
		}
	</script>
	
</head>
<body onLoad="writeCopyright()">
	<div class="main">
		
		<?php include("boilerplate.php"); ?>
		<?php include("loginnavigation.php"); ?>
		<?php connect('localhost','root','','gradegriddatabase');?>
		<?php
		
		$accountid_query = sprintf("SELECT account_id FROM account WHERE username = '%s'",
		                           mysql_real_escape_string($_SESSION["username"]));
		$accountid_array = mysql_fetch_array(mysql_query($accountid_query));
		$accountid = $accountid_array["account_id"];
		
		$query_class = sprintf("SELECT * FROM class WHERE account_id = '%s'",
		                       mysql_real_escape_string($accountid));
		$result_class=mysql_query($query_class);
		$num=mysql_num_rows($result_class);
		$query_course="SELECT * FROM course";
		$result_course=mysql_query($query_course);
		
		?>
		<?php if($_SESSION["logged_in"]): ?>
			<div style="float: left;">
			<a href="grid_classes.php" style="padding: 5px; width: 10%; text-align: center;">Grid View</a>
			<span style="background-color: #DADADA; padding: 5px; font-family: Arial; font-size: 13px; width: 10%; text-align: center;">List View</span><br /><br />
			<!--Some general menu stuff-->
			<input type="button" value="General Settings" onClick="location.href='settings.php?page=class'">
			<input type="button" value="Add class" onClick="window.open('new_class.php', '', 'width=500, height=500')"/>
			
			<form method="post" action="manage_template.php">
			<table border="0">
			
			<?php $i=0;
			while ($i < $num):
				
				$section = mysql_result($result_class,$i,"class_name"); 
				$class_id=mysql_result($result_class,$i,"class_id"); 
				$class_template=mysql_result($result_class,$i,"template_id"); 
				$course_id=mysql_result($result_class, $i,"course_id");
				
				$getcoursename_query = sprintf("SELECT course_name FROM course WHERE course_id = '%s'",
				                               mysql_real_escape_string($course_id));
				$coursename_array = mysql_fetch_array(mysql_query($getcoursename_query));
				$coursename = $coursename_array["course_name"];
				
				$query_grade="SELECT class_id FROM grade WHERE class_id='$class_id'";
				$result_grade=mysql_query($query_grade);
				$num_grade=mysql_numrows($result_grade);					//rows of grade table
				
				echo "<tr>";
				echo "<td align='right'><b class='pMirror'>";
				echo "$coursename - $section";
				
				?>
				</b></td>
				<!--<td><input type="button" value="Manage Class" onClick="location.href='settings.php?page=class'"></td>-->
				<td><input type="button" value="Delete" onClick="deleteClass(<?php echo "$class_id, '$coursename', '$section'"; ?>)"></td>
				<?php if ($num_grade > 0) { ?>
					<td><input type="button" value="Set/Change Rubric" disabled="disabled"></td>
				<?php }else {?>
					<?php echo "<td><input type='button' value='Set/Change Rubric' onclick='window.open(\"manage_rubrics.php?id=$class_id\", \"_newtab\")' /></td>" ?>
				<?php }
				 
				echo "<td><input type='hidden' name='classID' value='$class_id'></td>";
				echo "<td><input type='hidden' name='classtemplate' value='$class_template'></td>";?>
				<td><input type="button" value="View Class Record" onClick="window.open('record_operations.php<?php echo "?classid=$class_id";?>', '_newtab')"></td>
				</tr>
				<tr><td colspan="5" id="myclass<?php echo "$i";?>" align="center"></td></tr>
				
			<?php

			$i++;
			endwhile?>
			
			</table>
			</form>
			<?php 
			mysql_close();?>
			
			
			</p>
			</div>
		<?php else: ?>
			<?php executeFile("../files/access_error.txt"); ?>
		<?php endif ?>
	</div>
	<div id="copywright"></div>
</body>
</html>